package com.huike.web.controller.system;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huike.clues.domain.SysDictData;

import com.huike.clues.domain.dto.SysDictDataQueryDTO;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysDictDataDTO;
import com.huike.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController {
    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 分页查询
     * @param
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDictDataQueryDTO sysDictDataQueryDTO) {
        startPage();
        List<SysDictData> list = iSysDictDataService.selectAll(sysDictDataQueryDTO);
        return getDataTable(list);
    }

    //根据字典类型编码查询所有字典数据
    @GetMapping("/type/{dictType}")
    public AjaxResult getDictOption(@PathVariable String dictType) {

        List<SysDictData> list = iSysDictDataService.selectDictDataByType(dictType);
        return AjaxResult.success(list);
    }

    //新增字典数据
    @PostMapping
    public AjaxResult add(@RequestBody SysDictData sysDictData) {
        iSysDictDataService.Add(sysDictData);
        return AjaxResult.success();
    }


    //查询回显
    @GetMapping("/{dictCode}")
    public AjaxResult getdictcode(@PathVariable Integer dictCode) {
        SysDictData sysDictData = iSysDictDataService.getOne(Wrappers.<SysDictData>lambdaQuery().eq(SysDictData::getDictCode, dictCode));
        return AjaxResult.success(sysDictData);
    }

    //修改
    @PutMapping
    public AjaxResult update(@RequestBody SysDictData sysDictData) {
        // 添加参数校验
        if (sysDictData == null) {
            return AjaxResult.error("参数不能为空");
        }
        iSysDictDataService.updateById(sysDictData);
        return AjaxResult.success();
    }

    /**
     * 删除字典数据
     */
    @DeleteMapping("/{dictCodes}")
    public AjaxResult remove(@PathVariable String dictCodes) {
        iSysDictDataService.removeById(dictCodes);
        return AjaxResult.success();
    }

    /**
     * 字典导出
     */
   /* @GetMapping("/export")
    public AjaxResult export(SysDictDataQueryDTO sysDictDataQueryDTO) {
        List<SysDictData> list = iSysDictDataService.selectAll(sysDictDataQueryDTO);
        return AjaxResult.success(list);
    }*/
}
